package JSON_Temp_Test;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class RedTest extends Reducer<Temp, NullWritable, Temp, Temp> {
    Temp k = new Temp();
    Temp v = new Temp();
    int max_temp = -100;
    int min_temp = 100;
    String data_max = null;
    String data_min = null;
    int id_max = 0;
    int id_min = 0;

    @Override
    protected void reduce(Temp key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        for (NullWritable value : values) {
            if (max_temp < key.getTemp()) {
                max_temp = key.getTemp();
                data_max = key.getDate();
                id_max = key.getId();
            }
            if (min_temp > key.getTemp()) {
                min_temp = key.getTemp();
                data_min = key.getDate();
                id_min = key.getId();
            }
        }
        k.set(id_max, data_max, max_temp);
        v.set(id_min, data_min, min_temp);
        context.write(k, v);
        min_temp = 100;
        max_temp = -100;
    }
}
